"""
Based on original code by David Beazley (http://www.dabeaz.com).
"""


from wheels.pi.coro._SystemCall import SystemCall



# Return a task's ID number
class Tid(SystemCall):

    def exec_(self, kernel, tid):
        kernel._sys_tid(tid)



# Return a task's CMD string
class Cmd(SystemCall):

    def exec_(self, kernel, tid):
        kernel._sys_cmd(tid)



# Return a task's parent ID number
class Pid(SystemCall):

    def exec_(self, kernel, tid):
        kernel._sys_pid(tid)



# Send a signal
class Kill(SystemCall):

    def __init__(self, target_tid):
        self._target_tid = target_tid


    def exec_(self, kernel, tid):
        kernel._sys_kill(tid, self._target_tid)



# Create a new task
class Fork(SystemCall):

    def __init__(self, coro):
        self._coro = coro


    def exec_(self, kernel, tid):
        kernel._sys_fork(tid, self._coro)



# Wait for a task to exit
class Wait(SystemCall):

    def __init__(self, target_tid):
        self._target_tid = target_tid


    def exec_(self, kernel, tid):
        kernel._sys_wait(tid, self._target_tid)



# Exit
class Exit(SystemCall):

    def __init__(self, status):
        self._status = status


    def exec_(self, kernel, tid):
        kernel._sys_exit(tid, self._status)



# Halt kernel
class Halt(SystemCall):

    def exec_(self, kernel, task):
        kernel._sys_halt(task)



# Accept
class Accept(SystemCall):

    def __init__(self, handle):
        self._handle = handle


    def exec_(self, kernel, tid):
        kernel._sys_accept(tid, self._handle)



# Connect
class Connect(SystemCall):

    def __init__(self, handle, remote_address):
        self._handle = handle
        self._remote_address = remote_address


    def exec_(self, kernel, tid):
        kernel._sys_connect(tid, self._handle, self._remote_address)



# Recv
class Recv(SystemCall):

    def __init__(self, handle, len_):
        self._handle = handle
        self._len = len_


    def exec_(self, kernel, tid):
        kernel._sys_recv(tid, self._handle, self._len)



# Send
class Send(SystemCall):

    def __init__(self, handle, buf):
        self._handle = handle
        self._buf = buf


    def exec_(self, kernel, tid):
        kernel._sys_send(tid, self._handle, self._buf)
